package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.business.domain.bo.PlainBo;
import com.ruoyi.business.domain.vo.PlainVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.Plain;
import com.ruoyi.business.service.IPlainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计划管理Controller
 * 
 * @author 吴倩芸
 * @date 2023-03-09
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/plain")
public class PlainController extends BaseController
{
    @Autowired
    private IPlainService plainService;

    /**
     * 查询计划管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:plain:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlainBo plain)
    {
        startPage();
        List<PlainVo> list = plainService.selectPlainList(plain);
        return getDataTable(list);
    }

    /**
     * 查询我自己的计划
     * @return
     */
    @GetMapping("/list/my")
    public AjaxResult listMyPlain(PlainBo plain) {
        List<PlainVo> list = plainService.selectMyPlainList(plain);
        return success(list);
    }

    /**
     * 导出计划管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:plain:export')")
    @Log(title = "计划管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlainBo plain)
    {
        List<PlainVo> list = plainService.selectPlainList(plain);
        ExcelUtil<PlainVo> util = new ExcelUtil<PlainVo>(PlainVo.class);
        util.exportExcel(response, list, "计划管理数据");
    }

    /**
     * 获取计划管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:plain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(plainService.selectPlainById(id));
    }

    /**
     * 新增计划管理
     */
    @PreAuthorize("@ss.hasPermi('business:plain:add')")
    @Log(title = "计划管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Plain plain)
    {
        return toAjax(plainService.insertPlain(plain));
    }

    /**
     * 修改计划管理
     */
    @PreAuthorize("@ss.hasPermi('business:plain:edit')")
    @Log(title = "计划管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Plain plain)
    {
        return toAjax(plainService.updatePlain(plain));
    }

    /**
     * 删除计划管理
     */
    @PreAuthorize("@ss.hasPermi('business:plain:remove')")
    @Log(title = "计划管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(plainService.deletePlainByIds(ids));
    }
}
